//
//  SGJMapTaskViewController.m
//  Sewage
//
//  Created by 优聚泰元 on 2017/6/7.
//  Copyright © 2017年 宗庆猛. All rights reserved.
//

#import "SGJMapTaskViewController.h"

#import <AMap3DMap/MAMapKit/MAMapView.h>

#import <MAMapKit/MAPolyline.h>

#import <MAMapKit/MAPolylineRenderer.h>

@interface SGJMapTaskViewController ()<MAMapViewDelegate>

@property (nonatomic,strong) MAMapView *mapView;

@end

@implementation SGJMapTaskViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.mapView = [[MAMapView alloc] initWithFrame:self.view.bounds];
    self.mapView.delegate = self;
    [self.view addSubview:self.mapView];
    
    self.mapView.showsScale = NO;
    self.mapView.rotateCameraEnabled = NO;
    self.mapView.showsUserLocation = YES;//显示用户的位置
    
    self.mapView.userTrackingMode = MAUserTrackingModeFollow;
    
    
    
    
    //构造折线数据对象
    NSInteger count = self.tempObject.poiRecords.count;
    CLLocationCoordinate2D commonPolylineCoords[count];
    commonPolylineCoords[0].latitude = [self.tempObject.poiRecords[0].poiLat integerValue];
    commonPolylineCoords[0].longitude = [self.tempObject.poiRecords[0].poiLng integerValue];
    
    commonPolylineCoords[1].latitude = [self.tempObject.poiRecords[1].poiLat integerValue];
    commonPolylineCoords[1].longitude = [self.tempObject.poiRecords[1].poiLng integerValue];
    
    for (int i = 0; i < self.tempObject.poiRecords.count; i ++) {
        commonPolylineCoords[i].latitude = [self.tempObject.poiRecords[i].poiLat integerValue];
        commonPolylineCoords[i].longitude = [self.tempObject.poiRecords[i].poiLng integerValue];

    }
    
//    CLLocationCoordinate2D commonPolylineCoords[4];
//    commonPolylineCoords[0].latitude = 39.832136;
//    commonPolylineCoords[0].longitude = 116.34095;
//    
//    commonPolylineCoords[1].latitude = 39.832136;
//    commonPolylineCoords[1].longitude = 116.42095;
    
    
//    commonPolylineCoords[2].latitude = 39.902136;
//    commonPolylineCoords[2].longitude = 116.42095;
//    
//    commonPolylineCoords[3].latitude = 39.902136;
//    commonPolylineCoords[3].longitude = 116.44095;
    
    //构造折线对象
    MAPolyline *commonPolyline = [MAPolyline polylineWithCoordinates:commonPolylineCoords count:count];
    
    //在地图上添加折线对象
    [_mapView addOverlay: commonPolyline];
}

- (MAOverlayRenderer *)mapView:(MAMapView *)mapView rendererForOverlay:(id <MAOverlay>)overlay
{
    if ([overlay isKindOfClass:[MAPolyline class]])
    {
        MAPolylineRenderer *polylineRenderer = [[MAPolylineRenderer alloc] initWithPolyline:overlay];
        
        polylineRenderer.lineWidth    = 8.f;
        polylineRenderer.strokeColor  = [UIColor colorWithRed:0 green:1 blue:0 alpha:0.6];
        polylineRenderer.lineJoinType = kMALineJoinRound;
        polylineRenderer.lineCapType  = kMALineCapRound;
        
        return polylineRenderer;
    }
    return nil;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
